package org.zty.db;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.zty.db.POJOAttr.Type;
import org.zty.util.FileUtil;
import org.zty.util.ZException;

public class SpringBootTools {
	String basePath = "d:/coderHelper_file/";
	String controllerPath = basePath+"controller/";
	String servicePath = basePath+"service/";
	String webPath = basePath+"webapps/";
	String processPath = basePath+"process/";
	String repositoryPath = basePath+"repository/";
	String pojoPath = basePath+"pojo/";
	
	/**
	 * packageName = "pers.zty."
	 */
	String packageName ="com.gd.";
	//String packageName ="pers.zty.";
	
	
	/**
	 * 是否为标准表结构.如果为标准表结构则需要有id state createTime operateTime state(逻辑删除1正常 0删除) remark version(用于乐观锁);
	 * true 需表结构支持
	 * false 不支持标准字段.一般是反向生成已有表结构时使用.新项目建议为true
	 */
	boolean isStandardPojo = true;
	
	/**
	 * 以下两个SB是给生成JS用的
	 */
	StringBuffer jsActionblock = new StringBuffer();
	StringBuffer jsBblock = new StringBuffer();
	
	StringBuffer menuBlock = new StringBuffer();
	StringBuffer i18nBlock = new StringBuffer();
	FileUtil fu = new FileUtil();
	
	public SpringBootTools(String driver, String url, String username, String password) {
		super();
		this.driver = driver;
		this.url = url;
		this.username = username;
		this.password = password;
	}
	
	private List<POJOAttr> parseMySQLData(List<String[]> list){
		List<POJOAttr> pojoAttrList = new ArrayList<POJOAttr>();
		for(String[] item : list){
			POJOAttr p = new POJOAttr();
			p.setName(getFirstSmallName(item[0]).trim()) ;
			Type type = null;
			if("int".equals(item[1].toLowerCase().trim())||item[1].toLowerCase().indexOf("int")!=-1){
				type=Type.INT;
			}
			
			if("bigint".equals(item[1].toLowerCase().trim())){
				type=Type.LONG;
			}else if(item[1].toLowerCase().indexOf("char")!=-1){
				type=Type.STRING;
			}else if(item[1].toLowerCase().indexOf("date")!=-1||item[1].toLowerCase().indexOf("time")!=-1){
				type=Type.DATE;
			}
			p.setType(type);
			p.setLength(Integer.parseInt(item[2]));
			pojoAttrList.add(p);
		}
		return pojoAttrList;
	}
	private void checkFilePath(){
		fu.mkdirs(webPath);
		fu.mkdirs(controllerPath);
		fu.mkdirs(servicePath);
		fu.mkdirs(processPath);
		fu.mkdirs(pojoPath);
		fu.mkdirs(repositoryPath);
	}
	
	private String driver;
	private String url;
	private String username;
	private String password;
	
	
	
	
	public void createCurTable(String curTable) throws SQLException{
		List<String[]> list = JDBC.getTableDesc(curTable, driver, url, username, password);
		checkFilePath();
		List<POJOAttr> pojoAttrList = parseMySQLData(list);
		String pkName = JDBC.getPrimaryKey(curTable, driver, url, username, password);
		if(pkName == null){
			System.out.println("表名:"+curTable+"没有主键!!!" );
		}else{
			for(POJOAttr attr:pojoAttrList){
				if(attr.getName().equals(getFirstSmallName(pkName))){
					attr.setPK(true);
				}
			}
		}
		createHtmlFile(curTable,pojoAttrList);
		appendJsActionBlockStr(curTable, pojoAttrList);
		appendJsBBlockStr(curTable, pojoAttrList);
		appendMenu(curTable, pojoAttrList);
		appendI18n(curTable, pojoAttrList);
		createJavaFile(curTable, pojoAttrList);
		createJSfile();
		createMenu();
		createI18n();
	}
	
	private void createI18n(){
		try {
			fu.crFile(i18nBlock.toString(), webPath+"i18n.properties", "UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void createMenu(){
		try {
			fu.crFile(menuBlock.toString(), webPath+"menu.html", "UTF-8");
		} catch (ZException e) {
			e.printStackTrace();
		}
	}
	
	public void createAll(List<String> tables) throws SQLException{
		System.out.println("立即生成!");
		System.out.println("生成中...");
		for(String curTable:tables){
			List<String[]> list = JDBC.getTableDesc(curTable, driver, url, username, password);
			checkFilePath();
			List<POJOAttr> pojoAttrList = parseMySQLData(list);
			
			String pkName = JDBC.getPrimaryKey(curTable, driver, url, username, password);
			if(pkName == null){
				System.out.println("表名:"+curTable+"没有主键!!!" );
			}else{
				for(POJOAttr attr:pojoAttrList){
					if(attr.getName().equals(getFirstSmallName(pkName))){
						attr.setPK(true);
					}
				}
			}
			createHtmlFile(curTable,pojoAttrList);
			appendJsActionBlockStr(curTable, pojoAttrList);
			appendJsBBlockStr(curTable, pojoAttrList);
			appendMenu(curTable, pojoAttrList);
			appendI18n(curTable, pojoAttrList);
			createJavaFile(curTable, pojoAttrList);
		}
		createJSfile();
		createMenu();
		createI18n();
		System.out.println("生成完毕");
	}
	
	public String getFirstBigName(String name){
	     return underline2Camel(name,false);
	}
	
	public String getFirstSmallName(String name){
	     return underline2Camel(name,true);
	}
	
	public void createJavaFile(String curTable,List<POJOAttr> pojoAttrList){
		createControllerJavaSrc(curTable, pojoAttrList);
		createServiceJavaSrc(curTable, pojoAttrList);
		createPojoJavaSrc(curTable, pojoAttrList);
		createRepositoryJavaSrc(curTable, pojoAttrList);
		createProcessJavaSrc(curTable, pojoAttrList);
	}
	
	/**
	 * 生成xxx.html
	 */
	public void createHtmlFile(String curTable,List<POJOAttr> pojoAttrList){
		
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		fu.mkdirs(webPath+fsName);
		/**
		 * 下面会生成一个很长很长的文件
		 */
		StringBuffer sb= new StringBuffer();
		sb.append("<!DOCTYPE html>\r\n");
		sb.append("<html>\r\n");
		sb.append("<head>\r\n");
		sb.append("    <meta charset=\"utf-8\">\r\n");
		sb.append("    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n");
		sb.append("    <title>"+fbName+"</title>\r\n");
		sb.append("    <!-- Tell the browser to be responsive to screen width -->\r\n");
		sb.append("    <meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\" name=\"viewport\">\r\n");
		sb.append("    <meta id=\"i18n_pagename\" content=\"ui\">\r\n");
		sb.append("    <script src=\"../../js/import.js\"></script>\r\n");
		sb.append("    <script src=\"../../js/init.js\"></script>\r\n");
		sb.append("</head>\r\n");
		sb.append("<body class=\"hold-transition iframe_content_body\" >\r\n");
		sb.append("<!-- Content Wrapper. Contains page content -->\r\n");
		sb.append("<div >\r\n");
		sb.append("    <!-- Content Header (Page header) -->\r\n");
		sb.append("    <section class=\"content-header\">\r\n");
		sb.append("        <h1>\r\n");
		sb.append("            <span class=\"i18n\" i18nKey=\"resource."+fsName+"\">"+fbName+"</span>\r\n");
		sb.append("            <small class=\"i18n\" i18nKey=\"controlPanel\">Control panel</small>\r\n");
		sb.append("        </h1>\r\n");
		sb.append("        <ol class=\"breadcrumb\">\r\n");
		sb.append("            <li><a href=\"/dashboard.html\"><i class=\"fa fa-dashboard\"></i> <span class=\"i18n\" i18nKey=\"home\">Home</span></a></li>\r\n");
		sb.append("            <li class=\"active\"><a href=\"#\" onclick=\"location.reload()\"><span class=\"i18n\" i18nKey=\"resource."+fsName+"\">"+fbName+"</span></a></li>\r\n");
		sb.append("        </ol>\r\n");
		sb.append("\r\n");
		sb.append("    </section>\r\n");
		sb.append("\r\n");
		sb.append("    <section class=\"content\">\r\n");
		sb.append("        	<div id=\"tip_block\"></div>\r\n");
		sb.append("        <div class=\"row d_s inner_page list_block\">\r\n");
		sb.append("        	<!-- 提示框 -->\r\n");
		sb.append("            <div class=\"col-xs-12\">\r\n");
		sb.append("                <div class=\"box\">\r\n");
		sb.append("                    <div class=\"box-header\" style=\"position: relative;\">\r\n");
		sb.append("                    	<div style=\"margin-right:300px;width:auto;\">\r\n");
		sb.append("                                   <form id=\"searchForm1\" class=\"searchForm\" name=\"searchForm1\">\r\n");
		sb.append("                                       <table>\r\n");
		sb.append("                                           <tbody>\r\n");
		for(int i =0;i<pojoAttrList.size();i++){
			POJOAttr attr = pojoAttrList.get(i);
			if(i%3==0){
				sb.append("                                           <tr>\r\n");
			}
			if(attr.getType()==Type.DATE){
				sb.append("                                               <td><label class=\"i18n\" i18nKey=\"resource."+fsName+"."+attr.getName()+"\" for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label></td>\r\n");
				sb.append("                                               <td><input name=\""+attr.getName()+"Start\" dataPickerName=\""+attr.getName()+"\" class=\"ml-10 mr-10 dataPickerItem dataPickerInput\" type=\"text\">-<input name=\""+attr.getName()+"End\" class=\"ml-10 mr-10 dataPickerInput\" type=\"text\"></td>\r\n\r\n");
			}else{
				sb.append("                                               <td><label class=\"i18n\" i18nKey=\"resource."+fsName+"."+attr.getName()+"\" for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label></td>\r\n");
				sb.append("                                               <td><input name=\""+attr.getName()+"\" class=\"ml-10 mr-10\" type=\"text\"></td>\r\n\r\n");
			}
			if(i%3==2){
				sb.append("                                           </tr>\r\n");
				sb.append("                                           <tr style=\"height:10px;\"></tr>\r\n");
			}
			if(i==pojoAttrList.size()-1&&i%3!=2){
				//最后一个
				for(int j =0;j<(2-i%3);j++){
					sb.append("                                               <td></td>\r\n                                               <td></td>\r\n");
				}
				sb.append("                                           </tr>\r\n");
				sb.append("                                           <tr style=\"height:10px;\"></tr>\r\n");
			}
		}
		sb.append("                                           </tbody>\r\n");
		sb.append("                                       </table>\r\n");
		sb.append("                                   </form>\r\n");
		
		sb.append("                    	</div>\r\n");
		sb.append("                    	<div style=\"position:absolute;right:10px;top:10px;width:275px;\">\r\n");
		sb.append("                        	<div class=\"btn btn-default fright\" onclick=\"b."+fsName+".add"+fbName+"('form2')\"><i class=\"fa fa-fw fa-plus-circle mr-10\"></i>新增</div>\r\n");
		sb.append("                        	<div class=\"btn btn-default fright\" onclick=\"$('#searchForm1')[0].reset()\" style=\"margin-right:10px;\" ><i class=\"fa fa-fw fa-retweet mr-10\"></i>重置</div>\r\n");
		sb.append("                        	<div class=\"btn btn-default fright\" onclick=\"b."+fsName+".search"+fbName+"()\" style=\"margin-right:10px;\" ><i class=\"fa fa-fw fa-search mr-10\"></i>搜索</div>\r\n");
		sb.append("                    	</div>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <div class=\"box-body\">\r\n");
		sb.append("                        <div id=\"example2_wrapper\" class=\"dataTables_wrapper form-inline dt-bootstrap\">\r\n");
		sb.append("                            <div class=\"row\">\r\n");
		sb.append("                                <div class=\"col-sm-12\">\r\n");
		
		sb.append("                                    <table id=\"datatable\" class=\"table table-bordered table-hover dataTable\" role=\"grid\" aria-describedby=\"example2_info\">\r\n");
		sb.append("                                    <thead>\r\n");
		sb.append("                                    <tr role=\"row\">\r\n");
		
		for(POJOAttr attr : pojoAttrList){
			sb.append("                                        <th class=\"sorting i18n\" i18nKey=\"resource."+fsName+"."+attr.getName()+"\" tabindex=\"0\" aria-controls=\"example2\" rowspan=\"1\" colspan=\"1\" aria-label=\"Rendering engine: activate to sort column ascending\">"+attr.getFirstBigName()+"</th>\r\n");	
		}
		sb.append("												<th class=\"sorting i18n\" i18nKey=\"control\">Control</th>\r\n											</tr>\r\n");
		sb.append("                                    </thead>\r\n");
		sb.append("                                    <tbody>\r\n");
		sb.append("\r\n");
		sb.append("                                    </tbody>\r\n");
		sb.append("                                    </table>\r\n");
		sb.append("                                    <div id=\"page_bar\"></div>\r\n");
		sb.append("                                </div>\r\n");
		sb.append("                            </div>\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-body -->\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("            <!-- /.col -->\r\n");
		sb.append("        </div>\r\n");
		sb.append("        <!-- /.row -->\r\n");
		sb.append("\r\n");
		sb.append("        <div class=\"row d_n inner_page update_form_block\">\r\n");
		sb.append("            <div class=\"col-md-6\">\r\n");
		sb.append("                <!-- general form elements -->\r\n");
		sb.append("                <div class=\"box box-primary\">\r\n");
		sb.append("                    <div class=\"box-header with-border\">\r\n");
		sb.append("                        <h3 class=\"box-title\">Form</h3>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <!-- form start -->\r\n");
		sb.append("                    <form role=\"form\" id=\"form1\" name=\"form1\">\r\n");
		sb.append("                        <div class=\"box-body\">\r\n");
		
		for(POJOAttr attr:pojoAttrList){
			if(attr.getName().equals(getIdName(pojoAttrList))){
				sb.append("                               <input type=\"hidden\" class=\"form-control\" id=\"update_"+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
				continue;
			}
			sb.append("                            <div class=\"form-group\">\r\n");
			sb.append("                                <label class=\"i18n\" i18nKey=\"resource."+fsName+"."+attr.getName()+"\" for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label>\r\n");
			sb.append("                                <span class=\"text-red\" ></span>\r\n");
			sb.append("                                <input type=\"text\" class=\"form-control\" id=\"update_"+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
			sb.append("                            </div>\r\n");
		}
		sb.append("                        </div>\r\n");
		sb.append("\r\n");
		sb.append("                        <!-- /.box-body -->\r\n");
		sb.append("                        <div class=\"box-footer\">\r\n");
		sb.append("                            <button type=\"button\" class=\"btn btn-primary\" onclick=\"b."+fsName+".submit"+fbName+"('form1')\">Submit</button>\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </form>\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("        </div>\r\n");
		
		sb.append("        <div class=\"row d_n inner_page add_form_block\">\r\n");
		sb.append("            <div class=\"col-md-6\">\r\n");
		sb.append("                <!-- general form elements -->\r\n");
		sb.append("                <div class=\"box box-primary\">\r\n");
		sb.append("                    <div class=\"box-header with-border\">\r\n");
		sb.append("                        <h3 class=\"box-title\">Form</h3>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <!-- form start -->\r\n");
		sb.append("                    <form role=\"form\" id=\"form2\" name=\"form2\">\r\n");
		sb.append("                        <div class=\"box-body\">\r\n");
		
		for(POJOAttr attr:pojoAttrList){
			if(idExists(pojoAttrList)&&attr.getName().equals(getIdName(pojoAttrList))){
				continue;
			}
			sb.append("                            <div class=\"form-group\">\r\n");
			sb.append("                                <label class=\"i18n\" i18nKey=\"resource."+fsName+"."+attr.getName()+"\" for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label>\r\n");
			sb.append("                                <span class=\"text-red\" ></span>\r\n");
			sb.append("                                <input type=\"text\" class=\"form-control\" id=\"add_"+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
			sb.append("                            </div>\r\n");
		}
		sb.append("                        </div>\r\n");
		sb.append("\r\n");
		sb.append("                        <!-- /.box-body -->\r\n");
		sb.append("                        <div class=\"box-footer\">\r\n");
		sb.append("                            <button type=\"button\" class=\"btn btn-primary\" onclick=\"b."+fsName+".submit"+fbName+"('form2')\">Submit</button>\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </form>\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("        </div>\r\n");
		
		
		sb.append("        <div class=\"row d_n inner_page view_block\">\r\n");
		sb.append("            <div class=\"col-md-6\">\r\n");
		sb.append("                <!-- general form elements -->\r\n");
		sb.append("                <div class=\"box box-primary\">\r\n");
		sb.append("                    <div class=\"box-header with-border\">\r\n");
		sb.append("                        <h3 class=\"box-title\">Form</h3>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <!-- form start -->\r\n");
		sb.append("                    <form role=\"form\" id=\"form3\" name=\"form3\">\r\n");
		sb.append("                        <div class=\"box-body\">\r\n");
		
		for(POJOAttr attr:pojoAttrList){
			sb.append("                            <div class=\"form-group\">\r\n");
			sb.append("                                <label class=\"i18n\" i18nKey=\"resource."+fsName+"."+attr.getName()+"\" for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label>\r\n");
			sb.append("                                <input disabled type=\"text\" class=\"form-control\" id=\""+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
			sb.append("                            </div>\r\n");
		}
		sb.append("                        </div>\r\n");
		sb.append("\r\n");
		sb.append("                        <!-- /.box-body -->\r\n");
		sb.append("                        <div class=\"box-footer\">\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </form>\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("        </div>\r\n");
		
		sb.append("\r\n");
		sb.append("    </section>\r\n");
		sb.append("    <!-- /.content -->\r\n");
		sb.append("</div>\r\n");
		sb.append("<script>\r\n");
		sb.append("    $(document).ready(function(){\r\n");
		sb.append("        b."+fsName+".find"+fbName+"List();\r\n");
		sb.append("    });\r\n");
		sb.append("</script>\r\n");
		sb.append("</body>\r\n");
		sb.append("</html>\r\n");
		try {
			fu.crFile(sb.toString(), webPath+fsName+"/"+fsName+".html", "UTF-8");
		} catch (ZException e) {
			e.printStackTrace();
		}
	}
	
	private void appendMenu(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		
		StringBuffer sb = new StringBuffer();
		sb.append("<li><a href=\"business/"+fsName+"/"+fsName+".html\" target=\"main_content\"><i class=\"fa fa-circle-o\"></i> <span class=\"i18n\" i18nKey=\"resource."+fsName+"\">"+fbName+"</span></a></li>\r\n");
		menuBlock.append(sb);
	}
	
	private void appendI18n(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append("resource."+fsName+"="+fbName+"\r\n");
		for(POJOAttr attr : pojoAttrList){
			sb.append("resource."+fsName+"."+attr.getName()+"="+attr.getFirstBigName()+"\r\n");
		}
		i18nBlock.append(sb);
	}
	
	private void appendJsActionBlockStr(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		
		StringBuffer sb = new StringBuffer();
		sb.append("	"+fsName+":{\r\n");
		sb.append("		find"+fbName+"List:\"/"+fsName+"/list\",\r\n");
		sb.append("		get"+fbName+":\"/"+fsName+"/get\",\r\n");
		sb.append("		update"+fbName+":\"/"+fsName+"/update\",\r\n");
		sb.append("		add"+fbName+":\"/"+fsName+"/create\",\r\n");
		sb.append("		delete"+fbName+":\"/"+fsName+"/delete\"\r\n");
		sb.append("	},\r\n");
		jsActionblock.append(sb);
	}
	
	private void appendJsBBlockStr(String curTable,List<POJOAttr> pojoAttrList){
		
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append(fsName+":{\r\n");
		sb.append("    find"+fbName+"List:function(searchData){\r\n");
		sb.append("        switchPage(\"list_block\");\r\n");
		sb.append("        showList(searchData,action."+fsName+".find"+fbName+"List,function(item){\r\n");
		sb.append("            var tdStr =\"\";\r\n");
		sb.append("            	tdStr+=\"<tr>\";\r\n");
		for(POJOAttr attr :pojoAttrList){
		    sb.append("    			tdStr+=\"<td>\"+item."+attr.getName()+"+\"</td>\";\r\n");
		}

		sb.append("    			tdStr+=\"<td width='210'>"
		        + "    <button type='button' class='btn btn-primary' onclick='b."+fsName+".update"+fbName+"(\\\"form1\\\",\\\"\"+item."+getIdName(pojoAttrList)+"+\"\\\")'>修改</button>"
		        + "    <button type='button' class='btn btn-danger ml-10' onclick='parent.cfm(\\\"确认删除?\\\",function(){b."+fsName+".delete"+fbName+"(\\\"\"+item."+getIdName(pojoAttrList)+"+\"\\\")},\\\"danger\\\")'>删除</button>"
		        + "    <button type='button' class='btn btn-success ml-10' onclick='b."+fsName+".get"+fbName+"(\\\"form3\\\",\\\"\"+item."+getIdName(pojoAttrList)+"+\"\\\")'>查看</button>"
		        + "    </td>\";\r\n");
		sb.append("    		tdStr+=\"</tr>\";\r\n");
		sb.append("            return tdStr;\r\n");
		sb.append("        },b."+fsName+".find"+fbName+"List);\r\n");
		sb.append("    },\r\n");
		sb.append("    search"+fbName+":function(){\r\n");
		sb.append("        var searchData = getFormData(\"searchForm1\");\r\n");
		sb.append("        b."+fsName+".find"+fbName+"List(searchData);\r\n");
		sb.append("    },\r\n");
		sb.append("    get"+fbName+":function(formId,id){\r\n");
		sb.append("        switchPage(\"view_block\");\r\n");
		sb.append("        $(\"#\"+formId)[0].reset();\r\n");
		sb.append("        if(id==null){\r\n");
		sb.append("            return;\r\n");
		sb.append("        }\r\n");
		sb.append("        postData(action."+fsName+".get"+fbName+",{\""+getIdName(pojoAttrList)+"\":id},function(data){\r\n");
		sb.append("            $(\"#\"+formId).populateForm(data.object);\r\n");
		sb.append("        })\r\n");
		sb.append("    },\r\n");
		sb.append("    update"+fbName+":function(formId,id){\r\n");
		sb.append("        switchPage(\"update_form_block\");\r\n");
		sb.append("        $(\"#\"+formId)[0].reset();\r\n");
		sb.append("        if(id==null){\r\n");
		sb.append("            return;\r\n");
		sb.append("        }\r\n");
		sb.append("        postData(action."+fsName+".get"+fbName+",{\""+getIdName(pojoAttrList)+"\":id},function(data){\r\n");
		sb.append("            $(\"#\"+formId).populateForm(data.object);\r\n");
		sb.append("        })\r\n");
		sb.append("    },\r\n");
		sb.append("    add"+fbName+":function(formId){\r\n");
		sb.append("        switchPage(\"add_form_block\");\r\n");
		sb.append("        $(\"#\"+formId)[0].reset();\r\n");
		sb.append("    },\r\n");
		sb.append("    submit"+fbName+":function(formId){\r\n");
		sb.append("        var valid = $(\"#\"+formId).valid();\r\n");
		sb.append("        if(!valid)\r\n");
		sb.append("            return;\r\n");
		sb.append("        if($(\"#\"+formId+\" input[name="+getIdName(pojoAttrList)+"]\").length==0||$(\"#\"+formId+\" input[name="+getIdName(pojoAttrList)+"]\").val().trim().length==0){\r\n");
		sb.append("            //代表是新增\r\n");
		sb.append("            postData(action."+fsName+".add"+fbName+",getFormData(formId),function(data){\r\n");
		sb.append("                $(\"#\"+formId)[0].reset();\r\n");
		sb.append("                b."+fsName+".find"+fbName+"List();\r\n");
		sb.append("            });\r\n");
		sb.append("        }else{\r\n");
		sb.append("            postData(action."+fsName+".update"+fbName+",getFormData(formId),function(data){\r\n");
		sb.append("                $(\"#\"+formId)[0].reset();\r\n");
		sb.append("                b."+fsName+".find"+fbName+"List();\r\n");
		sb.append("            });\r\n");
		sb.append("        }\r\n");
		sb.append("    },\r\n");
		sb.append("    delete"+fbName+":function(id){\r\n");
		sb.append("        postData(action."+fsName+".delete"+fbName+",{\""+getIdName(pojoAttrList)+"\":id},function(data){\r\n");
		sb.append("            b."+fsName+".find"+fbName+"List();\r\n");
		sb.append("        });\r\n");  
		sb.append("    }\r\n");
		sb.append("},\r\n");
		jsBblock.append(sb);
	}
	
	public void createJSfile(){
		fu.mkdirs(webPath+"js/");
		StringBuffer jsStr = new StringBuffer();
		jsStr.append("var action = {\r\n");
		/**
		 * 下面这句话就是为了去掉最后一个"," T.T
		 */
		jsStr.append(jsActionblock.substring(0,jsActionblock.toString().lastIndexOf(","))+jsActionblock.substring(jsActionblock.toString().lastIndexOf(",")+1));
		
		jsStr.append("}\r\n");
		try {
			fu.crFile(jsStr.toString(), webPath+"js/action.js", "UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		jsStr = new StringBuffer();
		jsStr.append("var b ={\r\n");
		jsStr.append(jsBblock.substring(0,jsBblock.toString().lastIndexOf(","))+jsBblock.substring(jsBblock.toString().lastIndexOf(",")+1));
		jsStr.append("}\r\n");
		try {
			fu.crFile(jsStr.toString(), webPath+"js/business.js", "UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void createControllerJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();
		
		
		/**
		 * 先查看ID的type
		 */
		String type = getIdName(pojoAttrList);
		if(getIdType(pojoAttrList)==Type.INT){
			type = "Integer.parseInt("+getIdName(pojoAttrList)+")";
		}
		if(getIdType(pojoAttrList)==Type.LONG){
			type = "Long.parseLong("+getIdName(pojoAttrList)+")";
		}
		
		sb.append("package "+packageName+"business.controller;\r\n");
		sb.append("\r\n");
		sb.append("import java.util.ArrayList;\r\n");
		sb.append("import java.util.HashMap;\r\n");
		sb.append("import java.util.Date;\r\n");
		sb.append("import java.util.List;\r\n");
		sb.append("import java.util.Map;\r\n");
		sb.append("\r\n");
		sb.append("import org.apache.commons.lang3.StringUtils;\r\n");
		sb.append("import org.apache.shiro.authz.annotation.Logical;\r\n");
		sb.append("import org.apache.shiro.authz.annotation.RequiresAuthentication;\r\n");
		sb.append("import org.apache.shiro.authz.annotation.RequiresPermissions;\r\n");
		sb.append("import org.springframework.beans.factory.annotation.Autowired;\r\n");
		sb.append("import org.springframework.data.domain.Page;\r\n");
		sb.append("import org.springframework.data.domain.Pageable;\r\n");
		sb.append("import org.springframework.data.domain.Sort;\r\n");
		sb.append("import org.springframework.data.domain.Sort.Direction;\r\n");
		sb.append("import org.springframework.web.bind.annotation.RequestBody;\r\n");
		sb.append("import org.springframework.web.bind.annotation.RequestMapping;\r\n");
		sb.append("import org.springframework.web.bind.annotation.RequestMethod;\r\n");
		sb.append("import org.springframework.web.bind.annotation.RestController;\r\n");
		sb.append("\r\n");
		sb.append("import io.swagger.annotations.Api;\r\n");
		sb.append("import io.swagger.annotations.ApiImplicitParam;\r\n");
		sb.append("import io.swagger.annotations.ApiImplicitParams;\r\n");
		sb.append("import io.swagger.annotations.ApiOperation;\r\n");
		sb.append("import lombok.extern.slf4j.Slf4j;\r\n");
		sb.append("import "+packageName+"business.domain."+fbName+";\r\n");
		sb.append("import "+packageName+"business.process."+fbName+"Process;\r\n");
		sb.append("import "+packageName+"business.property.PropertyBean;\r\n");
		sb.append("import "+packageName+"common.controller.CommonController;\r\n");
		sb.append("import "+packageName+"data.DataObjectResult;\r\n");
		sb.append("import "+packageName+"util.DateUtil;\r\n");
		sb.append("\r\n");
		sb.append("\r\n");
		sb.append("@RequiresAuthentication\r\n");
		sb.append("@RestController\r\n");
		sb.append("@RequestMapping(value=\"/"+fsName+"\")\r\n");
		sb.append("@Api(tags = \"API---"+fbName+"\")\r\n");
		sb.append("@Slf4j\r\n");
		sb.append("public class "+fbName+"Controller extends CommonController {\r\n");
		sb.append("\r\n");
		sb.append("	private final String MODULE_FLAG =\""+fbName+"\";\r\n");
		sb.append("	private final String AUTH_FLAG = \"+"+fbName+"+\";\r\n");
		sb.append("	@Autowired\r\n");
		sb.append("	private PropertyBean propertyBean;\r\n");
		sb.append("	@Autowired\r\n");
		sb.append("	private "+fbName+"Process "+fsName+"Process;\r\n");
		sb.append("	\r\n");
		sb.append("	//@RequiresAuthentication\r\n");
		sb.append("	//@RequiresPermissions(value={AUTH_FLAG + \"1\", AUTH_FLAG + \"2\"}, logical = Logical.OR)\r\n");
		sb.append("	@ApiOperation(value = \"创建\" + MODULE_FLAG, notes = \"创建\" + MODULE_FLAG)\r\n");
		sb.append("	@ApiImplicitParam(name = \"inputMap\", value = MODULE_FLAG + \"实体\", paramType = \"body\", dataType=\"SystemRole\", required = true)\r\n");
		sb.append("	@RequestMapping(value = \"/create\", method = RequestMethod.POST)\r\n");
		sb.append("	public DataObjectResult create(@RequestBody HashMap<String,Object> inputMap) {\r\n");
		sb.append("		"+fbName+" "+fsName+" = new "+fbName+"();\r\n");
		sb.append("\r\n");
		for(POJOAttr attr : pojoAttrList){
			if(isStandardPojo&&(attr.getName().equals("id")||attr.getName().equals("createTime")||attr.getName().equals("operateTime")||attr.getName().equals("state"))){
				continue;
			}
			if(attr.getType()==Type.LONG){
				sb.append("		if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("			Long "+attr.getName()+" = Long.parseLong((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
				sb.append("			"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
				sb.append("		}\r\n");
			}
			if(attr.getType()==Type.INT){
				sb.append("		if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("			Integer "+attr.getName()+" = Integer.parseInt((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
				sb.append("			"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
				sb.append("		}\r\n");
			}
			if(attr.getType()==Type.STRING){
				sb.append("		if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("			String "+attr.getName()+" = (String)inputMap.get(\""+attr.getName()+"\");\r\n");
				sb.append("			"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
				sb.append("		}\r\n");
			}
			if(attr.getType()==Type.DATE){
				sb.append("		if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("			Date "+attr.getName()+" = DateUtil.stringToFullDateNoSecond((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
				sb.append("			"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
				sb.append("		}\r\n");
			}
		}
		sb.append("		\r\n");
		sb.append("		this."+fsName+"Process.save("+fsName+");\r\n");
		sb.append("		\r\n");
		sb.append("		DataObjectResult dataObject = this.buildDataResult(this.getBaseConstant().getSuccessCommonCode());\r\n");
		sb.append("		return dataObject;\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		
		if(idExists(pojoAttrList)){
			sb.append("	//@RequiresAuthentication\r\n");
			sb.append("	//@RequiresPermissions(value={AUTH_FLAG + \"1\", AUTH_FLAG + \"4\"}, logical = Logical.OR)\r\n");
			sb.append("	@ApiOperation(value = \"删除\" + MODULE_FLAG, notes = \"根据ID删除\" + MODULE_FLAG)\r\n");
			sb.append("	@ApiImplicitParam(name = \"inputMap\", value = MODULE_FLAG + \"实体\", paramType = \"body\", dataType=\"HashMap\", required = true)\r\n");
			sb.append("	@RequestMapping(value = \"/delete\", method = RequestMethod.POST)\r\n");
			sb.append("	public DataObjectResult delete(@RequestBody HashMap<String,String> inputMap) {\r\n");
			sb.append("		String "+getIdName(pojoAttrList)+" = inputMap.get(\""+getIdName(pojoAttrList)+"\");\r\n");
			sb.append("		if (StringUtils.isNotBlank("+getIdName(pojoAttrList)+")) {\r\n");
			sb.append("			"+fbName+" "+fsName+" = this."+fsName+"Process.findOne("+type+");\r\n");
			sb.append("			if ("+fsName+" != null) {\r\n");
			sb.append("				this."+fsName+"Process.delete("+fsName+");\r\n");
			sb.append("			}\r\n");
			sb.append("		}\r\n");
			sb.append("		DataObjectResult dataObject = this.buildDataResult(this.getBaseConstant().getSuccessCommonCode());\r\n");
			sb.append("		return dataObject;\r\n");
			sb.append("	}\r\n");
			sb.append("\r\n");
			sb.append("	//@RequiresAuthentication\r\n");
			sb.append("	//@RequiresPermissions(value={AUTH_FLAG + \"1\", AUTH_FLAG + \"8\"}, logical = Logical.OR)\r\n");
			sb.append("	@ApiOperation(value = \"修改\" + MODULE_FLAG, notes = \"修改\" + MODULE_FLAG)\r\n");
			sb.append("	@ApiImplicitParam(name = \"inputMap\", value = MODULE_FLAG + \"实体\", paramType = \"body\", dataType=\"HashMap\", required = true)\r\n");
			sb.append("	@RequestMapping(value = \"/update\", method = RequestMethod.POST)\r\n");
			sb.append("	public DataObjectResult update(@RequestBody HashMap<String,Object> inputMap) {\r\n");
			sb.append("		String "+getIdName(pojoAttrList)+" = (String)inputMap.get(\""+getIdName(pojoAttrList)+"\");\r\n");
			sb.append("		if (StringUtils.isNotBlank("+getIdName(pojoAttrList)+")) {\r\n");
			sb.append("			"+fbName+" "+fsName+" = this."+fsName+"Process.findOne("+type+");\r\n");
			sb.append("			\r\n");
			for(POJOAttr attr : pojoAttrList){
				//这里不setID
				if(idExists(pojoAttrList)&&attr.getName().equals(getIdName(pojoAttrList))){
					continue;
				}
				
				if(isStandardPojo&&(attr.getName().equals("id")||attr.getName().equals("createTime")||attr.getName().equals("operateTime")||attr.getName().equals("state"))){
					continue;
				}
				
				if(attr.getType()==Type.LONG){
					sb.append("			if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
					sb.append("				Long "+attr.getName()+" = Long.parseLong((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
					sb.append("				"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
					sb.append("			}\r\n");
				}
				if(attr.getType()==Type.INT){
					sb.append("			if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
					sb.append("				Integer "+attr.getName()+" = Integer.parseInt((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
					sb.append("				"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
					sb.append("			}\r\n");
				}
				if(attr.getType()==Type.STRING){
					sb.append("			if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
					sb.append("				String "+attr.getName()+" = (String)inputMap.get(\""+attr.getName()+"\");\r\n");
					sb.append("				"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
					sb.append("			}\r\n");
				}
				if(attr.getType()==Type.DATE){
					sb.append("			if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
					sb.append("				Date "+attr.getName()+" = DateUtil.stringToFullDate((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
					sb.append("				"+fsName+".set"+attr.getFirstBigName()+"("+attr.getName()+");\r\n");
					sb.append("			}\r\n");
				}
			}
			sb.append("			\r\n");
			sb.append("			if ("+fsName+" != null) {\r\n");
			sb.append("				this."+fsName+"Process.update("+fsName+");\r\n");
			sb.append("			}\r\n");
			sb.append("		}\r\n");
			sb.append("\r\n");
			sb.append("		DataObjectResult dataObject = this.buildDataResult(this.getBaseConstant().getSuccessCommonCode());\r\n");
			sb.append("		return dataObject;\r\n");
			sb.append("	}\r\n");
			sb.append("	\r\n");
			
			
			sb.append("	//@RequiresAuthentication\r\n");
			sb.append("	//@RequiresPermissions(value={AUTH_FLAG + \"1\", AUTH_FLAG + \"16\"}, logical = Logical.OR)\r\n");
			sb.append("	@ApiOperation(value=\"根据ID获取\" + MODULE_FLAG, notes=\"\")\r\n");
			sb.append("	@ApiImplicitParam(name = \"inputMap\", value = MODULE_FLAG + \"实体\", paramType = \"body\", dataType=\"HashMap\", required = true)\r\n");
			sb.append("	@RequestMapping(value = \"/get\", method = RequestMethod.POST)\r\n");
			sb.append("	public DataObjectResult get(@RequestBody HashMap<String,String> inputMap) {\r\n");
			sb.append("		Map<String, Object> result = new HashMap<String, Object>();\r\n");
			sb.append("		String "+getIdName(pojoAttrList)+" = inputMap.get(\""+getIdName(pojoAttrList)+"\");\r\n");
			sb.append("		if(StringUtils.isNotBlank("+getIdName(pojoAttrList)+")) {\r\n");
			sb.append("			"+fbName+" "+fsName+" = this."+fsName+"Process.findOne("+type+");\r\n");
			sb.append("			if("+fsName+" != null) {\r\n");
			for(POJOAttr attr : pojoAttrList){
				if(attr.getType()==Type.LONG){
					sb.append("				result.put(\""+attr.getName()+"\", "+fsName+".get"+attr.getFirstBigName()+"());\r\n");
				}
				if(attr.getType()==Type.INT){
					sb.append("				result.put(\""+attr.getName()+"\", "+fsName+".get"+attr.getFirstBigName()+"());\r\n");
				}
				if(attr.getType()==Type.STRING){
					sb.append("				result.put(\""+attr.getName()+"\", "+fsName+".get"+attr.getFirstBigName()+"());\r\n");
				}
				if(attr.getType()==Type.DATE){
					sb.append("				result.put(\""+attr.getName()+"\", DateUtil.dateToFullString("+fsName+".get"+attr.getFirstBigName()+"()));\r\n");
				}
			}
			sb.append("			}\r\n");
			sb.append("		}\r\n");
			sb.append("		\r\n");
			sb.append("		Map<String, Object> map = new HashMap<String, Object>();\r\n");
			sb.append("		map.put(\"object\", result);\r\n");
			sb.append("		\r\n");
			sb.append("		DataObjectResult dataObject = this.buildDataResult(this.getBaseConstant().getSuccessCommonCode());\r\n");
			sb.append("		dataObject.setData(map);\r\n");
			sb.append("		return dataObject;\r\n");
			sb.append("	}\r\n");
			sb.append("	\r\n");
		}
		
		
		sb.append("	//@RequiresAuthentication\r\n");
		sb.append("	//@RequiresPermissions(value={AUTH_FLAG + \"1\", AUTH_FLAG + \"32\"}, logical = Logical.OR)\r\n");
		sb.append("	@ApiOperation(value=\"查询\" + MODULE_FLAG, notes=\"\")\r\n");
		sb.append("	@ApiImplicitParams({\r\n");
		sb.append("        @ApiImplicitParam(name = \"inputMap\", value = \"查询条件\", paramType=\"body\", required = false),\r\n");
		sb.append("	})\r\n");
		sb.append("	@RequestMapping(value = \"/list\", method = RequestMethod.POST)\r\n");
		sb.append("	public DataObjectResult list(@RequestBody Map<String, Object> inputMap) {\r\n");
		sb.append("		\r\n");
		if(isStandardPojo){
			sb.append("		Sort defaultSort = new Sort(Direction.DESC, \"createTime\");\r\n");
			sb.append("		Pageable pageable = this.buildInPage(inputMap, propertyBean.getCommon().getPageSize(), defaultSort);\r\n");
		}else{
			sb.append("		Pageable pageable = this.buildInPage(inputMap, propertyBean.getCommon().getPageSize());\r\n");
		}
		sb.append("		\r\n");
		sb.append("		Map<String,Object> searchMap = new HashMap<String,Object>();\r\n");
		sb.append("		//将值转化成 DATE INT LONG\r\n");
		for(POJOAttr attr : pojoAttrList){
			if(attr.getType()==Type.LONG){
				sb.append("	if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("		Long "+attr.getName()+" = Long.parseLong((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
				sb.append("		searchMap.put(\""+attr.getName()+"\","+attr.getName()+");\r\n");
				sb.append("	}\r\n");
			}
			if(attr.getType()==Type.INT){
				sb.append("	if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("		Integer "+attr.getName()+" = Integer.parseInt((String)inputMap.get(\""+attr.getName()+"\"));\r\n");
				sb.append("		searchMap.put(\""+attr.getName()+"\","+attr.getName()+");\r\n");
				sb.append("	}\r\n");
			}
			if(attr.getType()==Type.STRING){
				sb.append("	if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"\"))) {\r\n");
				sb.append("		String "+attr.getName()+" = (String)inputMap.get(\""+attr.getName()+"\");\r\n");
				sb.append("		searchMap.put(\""+attr.getName()+"\","+attr.getName()+");\r\n");
				sb.append("	}\r\n");
			}
			if(attr.getType()==Type.DATE){
				//默认按照时间段查询
				sb.append("	if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"Start\"))) {\r\n");
				sb.append("		String "+attr.getName()+"Start = (String)inputMap.get(\""+attr.getName()+"Start\");\r\n");
				sb.append("		if (StringUtils.isNotBlank("+attr.getName()+"Start)) {\r\n");
				sb.append("			Date date = DateUtil.stringToFullDate("+attr.getName()+"Start);\r\n");
				sb.append("			searchMap.put(\""+attr.getName()+"Start\",date);\r\n");
				sb.append("		}\r\n");
				sb.append("	}\r\n");
				
				sb.append("	if(StringUtils.isNotBlank((String)inputMap.get(\""+attr.getName()+"End\"))) {\r\n");
				sb.append("		String "+attr.getName()+"End = (String)inputMap.get(\""+attr.getName()+"End\");\r\n");
				sb.append("		if (StringUtils.isNotBlank("+attr.getName()+"End)) {\r\n");
				sb.append("			Date date = DateUtil.stringToFullDate("+attr.getName()+"End);\r\n");
				sb.append("			searchMap.put(\""+attr.getName()+"End\",date);\r\n");
				sb.append("		}\r\n");
				sb.append("	}\r\n");
			}
		}
		sb.append("		\r\n");
		sb.append("		Page<"+fbName+"> result = this."+fsName+"Process.findAll(searchMap, pageable);\r\n");
		sb.append("		\r\n");
		sb.append("		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();\r\n");
		sb.append("		result.forEach(entity -> {\r\n");
		sb.append("			Map<String, Object> tmp = new HashMap<String, Object>();\r\n");
		for(POJOAttr attr : pojoAttrList){
			if(attr.getType()==Type.LONG){
				sb.append("			tmp.put(\""+attr.getName()+"\", entity.get"+attr.getFirstBigName()+"());\r\n");
			}
			if(attr.getType()==Type.INT){
				sb.append("			tmp.put(\""+attr.getName()+"\", entity.get"+attr.getFirstBigName()+"());\r\n");
			}
			if(attr.getType()==Type.STRING){
				sb.append("			tmp.put(\""+attr.getName()+"\", entity.get"+attr.getFirstBigName()+"());\r\n");
			}
			if(attr.getType()==Type.DATE){
				sb.append("			tmp.put(\""+attr.getName()+"\", DateUtil.dateToFullString(entity.get"+attr.getFirstBigName()+"()));\r\n");
			}
		}
		sb.append("			resultList.add(tmp);\r\n");
		sb.append("		});\r\n");
		sb.append("		\r\n");
		sb.append("		Map<String, Object> map = new HashMap<String, Object>();\r\n");
		sb.append("		map.put(\"list\", resultList);\r\n");
		sb.append("		map.put(\"page\", this.buildOutPage(result));\r\n");
		sb.append("		\r\n");
		sb.append("		DataObjectResult dataObject = this.buildDataResult(this.getBaseConstant().getSuccessCommonCode());\r\n");
		sb.append("		dataObject.setData(map);\r\n");
		sb.append("		\r\n");
		sb.append("		return dataObject;\r\n");
		sb.append("	}\r\n");
		sb.append("	\r\n");
		sb.append("}\r\n");

		
		try {
			fu.crFile(sb.toString(),controllerPath+fbName+"Controller.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void createPojoJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append("package "+packageName+"business.domain;\r\n");
		sb.append("import java.io.Serializable;\r\n");
		sb.append("import java.util.Date;\r\n");
		sb.append("import javax.persistence.Column;\r\n");
		sb.append("import javax.persistence.Entity;\r\n");
		sb.append("import javax.persistence.Id;\r\n");
		sb.append("import javax.persistence.Index;\r\n");
		sb.append("import javax.persistence.Table;\r\n");
		sb.append("import org.hibernate.annotations.DynamicInsert;\r\n");
		sb.append("import org.hibernate.annotations.DynamicUpdate;\r\n");
		sb.append("import org.hibernate.annotations.OptimisticLockType;\r\n");
		sb.append("import org.hibernate.annotations.OptimisticLocking;\r\n");
		sb.append("import org.hibernate.annotations.Where;\r\n");
		sb.append("import org.hibernate.annotations.GenericGenerator;\r\n");
		sb.append("import javax.persistence.GeneratedValue;\r\n");
		sb.append("import org.hibernate.validator.constraints.Length;");
		sb.append("import org.springframework.format.annotation.DateTimeFormat;\r\n");
		sb.append("import com.fasterxml.jackson.annotation.JsonFormat;\r\n");
		sb.append("import "+packageName+"common.domain.PersistentDomain;\r\n");
		sb.append("import io.swagger.annotations.ApiModel;\r\n");
		sb.append("import lombok.Getter;\r\n");
		sb.append("import lombok.Setter;\r\n");
		sb.append("\r\n");
		sb.append("@Entity\r\n");
		if(isStandardPojo){
			//如果是标准POJO 则支持乐观锁和逻辑删除 并把id设置成主键
			sb.append("@OptimisticLocking(type = OptimisticLockType.VERSION)\r\n");
			sb.append("@Where(clause = \" state = '1' \")\r\n");
			
			/**
			 * 看看有没得ID的属性,如果有则设置成主键
			 */
			boolean idExists = idExists(pojoAttrList);
			
			sb.append("@Table(indexes = {\r\n");
			if(idExists){
				/**
				 *增加ID属性 
				 */
				sb.append("		@Index(columnList = \"id\", unique = false),\r\n");
			}
			sb.append("	})\r\n");
		}
		sb.append("@DynamicInsert(true)\r\n");
		sb.append("@DynamicUpdate(true)\r\n");
		sb.append("@ApiModel(value = \""+fbName+"\", description = \""+fbName+"缺省描述信息\")\r\n");
		sb.append("@Setter\r\n");
		sb.append("@Getter\r\n");
		sb.append("/**\r\n");
		sb.append("* \r\n");
		sb.append("* @author zty\r\n");
		sb.append("* 由coderHelper生成\r\n");
		sb.append("* 标准结构 isStandardPojo "+isStandardPojo+"\r\n");
		if(!isStandardPojo&&!idExists(pojoAttrList)){
			sb.append("* idExists "+idExists(pojoAttrList)+"***没有检查到ID字段存在*** 需检查逻辑是否为关联表\r\n");	
		}
		sb.append("* \r\n");
		sb.append("*/\r\n");
		sb.append("public class "+fbName+" ");
		if(isStandardPojo){
			//如果是标准POJO 则继承于PersistentDomain 将自动增加标准字段
			sb.append("extends PersistentDomain ");
		}
		sb.append("implements Serializable {\r\n");
		sb.append("	private static final long serialVersionUID = 1L;\r\n");
		sb.append("\r\n");
		for(POJOAttr attr : pojoAttrList){
			if(idExists(pojoAttrList)&&attr.getName().equals(getIdName(pojoAttrList))){
				sb.append("	@Id\r\n");
				sb.append("	@GenericGenerator(name = \"idGenerator\", strategy = \""+packageName+"common.generator.DistributedIdentifierGenerator\")\r\n");
				sb.append("	@GeneratedValue(generator = \"idGenerator\")\r\n");
			}
			if(attr.getType()==Type.LONG){
				sb.append("	@Column(name = \""+attr.getName()+"\")\r\n");
				sb.append("	private Long "+attr.getName()+";\r\n");
				sb.append("\r\n");
			}
			if(attr.getType()==Type.INT){
				sb.append("	@Column(name = \""+attr.getName()+"\")\r\n");
				sb.append("	private Integer "+attr.getName()+";\r\n");
				sb.append("\r\n");
			}
			if(attr.getType()==Type.STRING){
				sb.append("	@Column(length = "+attr.getLength()+", name = \""+attr.getName()+"\")\r\n	@Length(max = "+attr.getLength()+", min = 0, message = \"长度需要在{min}和{max}之间\")\r\n");
				sb.append("	private String "+attr.getName()+";\r\n");
				sb.append("\r\n");
			}
			if(attr.getType()==Type.DATE){
				sb.append("	@Column(name = \""+attr.getName()+"\")\r\n	@DateTimeFormat(pattern = \"yyyy-MM-dd HH:mm:ss\")\r\n	@JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")\r\n");
				sb.append("	private Date "+attr.getName()+";\r\n");
				sb.append("\r\n");
			}
		}
		sb.append("}\r\n");
		try {
			fu.crFile(sb.toString(),pojoPath+fbName+".java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void createServiceJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();
		
		/**
		 * 生成接口类
		 */
		sb.append("package "+packageName+"business.service;\r\n");
		sb.append("\r\n");
		sb.append("import java.util.Map;\r\n");
		sb.append("import org.springframework.data.domain.Page;\r\n");
		sb.append("import org.springframework.data.domain.Pageable;\r\n");
		sb.append("import org.springframework.data.repository.NoRepositoryBean;\r\n");
		sb.append("import "+packageName+"business.domain."+fbName+";\r\n");
		sb.append("\r\n");
		sb.append("@NoRepositoryBean\r\n");
		sb.append("public interface "+fbName+"Service {\r\n");
		sb.append("\r\n");
		sb.append("	public "+fbName+" save("+fbName+" entity);\r\n");
		sb.append("	\r\n");
		sb.append("	public "+fbName+" update("+fbName+" entity);\r\n");
		sb.append("	\r\n");
		sb.append("	public void delete( "+fbName+" entity);\r\n");
		sb.append("\r\n");
		if(idExists(pojoAttrList)){
			String type = "String";
			if(getIdType(pojoAttrList)==Type.INT){
				type = "Integer";
			}
			if(getIdType(pojoAttrList)==Type.LONG){
				type = "Long";
			}
			sb.append("	public "+fbName+" findOne("+type+" id);\r\n");
			sb.append("\r\n");
		}
		sb.append("	public "+fbName+" findOne(Map<String, Object> param);\r\n");
		sb.append("\r\n");
		sb.append("	public Page<"+fbName+"> findAll(Map<String, Object> param, Pageable pageable);\r\n");
		sb.append("	\r\n");
		sb.append("}\r\n");
		try {
			fu.crFile(sb.toString(),servicePath+fbName+"Service.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		/**
		 * 生成实现类
		 */
		sb = new StringBuffer();
		sb.append("package "+packageName+"business.service;\r\n");
		sb.append("import java.util.ArrayList;\r\n");
		sb.append("import java.util.Date;\r\n");
		sb.append("import java.util.List;\r\n");
		sb.append("import java.util.Map;\r\n");
		sb.append("import javax.persistence.criteria.CriteriaBuilder;\r\n");
		sb.append("import javax.persistence.criteria.CriteriaQuery;\r\n");
		sb.append("import javax.persistence.criteria.Predicate;\r\n");
		sb.append("import javax.persistence.criteria.Root;\r\n");
		sb.append("import org.apache.commons.lang3.StringUtils;\r\n");
		sb.append("import org.springframework.beans.factory.annotation.Autowired;\r\n");
		sb.append("import org.springframework.data.domain.Page;\r\n");
		sb.append("import org.springframework.data.domain.Pageable;\r\n");
		sb.append("import org.springframework.data.jpa.domain.Specification;\r\n");
		sb.append("import org.springframework.stereotype.Service;\r\n");
		sb.append("import org.springframework.transaction.annotation.Transactional;\r\n");
		sb.append("import "+packageName+"business.constants.WebConstants;\r\n");
		sb.append("import "+packageName+"business.domain."+fbName+";\r\n");
		sb.append("import "+packageName+"business.repository."+fbName+"Repository;\r\n");
		sb.append("import "+packageName+"util.DateUtil;\r\n");
		sb.append("\r\n");
		sb.append("@Service(\""+fsName+"Service\")\r\n");
		sb.append("@Transactional(readOnly = true)\r\n");
		sb.append("public class "+fbName+"ServiceImpl implements "+fbName+"Service {\r\n");
		sb.append("\r\n");
		sb.append("	@Autowired\r\n");
		sb.append("	private "+fbName+"Repository "+fsName+"Repository;\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	@Transactional(readOnly = false)\r\n");
		sb.append("	public "+fbName+" save("+fbName+" entity) {\r\n");
		sb.append("		return this."+fsName+"Repository.save(entity);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	@Transactional(readOnly = false)\r\n");
		sb.append("	public "+fbName+" update("+fbName+" entity) {\r\n");
		sb.append("		return this."+fsName+"Repository.save(entity);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	@Transactional(readOnly = false)\r\n");
		sb.append("	public void delete("+fbName+" entity) {\r\n");
		if(isStandardPojo){
			//标准pojo逻辑删除
			sb.append("		entity.setState(WebConstants.COMMON_ENTITY_DISABLED);\r\n");
			sb.append("		this."+fsName+"Repository.save(entity);\r\n");
		}else{
			//非标准物理删除 可能没有state字段
			sb.append("		this."+fsName+"Repository.delete(entity);\r\n");
		}
		sb.append("	}\r\n");
		sb.append("\r\n");
		if(idExists(pojoAttrList)){
			//如果ID存在才能按ID查
			String type = "String";
			if(getIdType(pojoAttrList)==Type.INT){
				type = "Integer";
			}
			if(getIdType(pojoAttrList)==Type.LONG){
				type = "Long";
			}
			
			if(type.equals("String")){
				sb.append("	@Override\r\n");
				sb.append("	public "+fbName+" findOne("+type+" id) {\r\n");
				sb.append("		return this."+fsName+"Repository.findOne(id);\r\n");
				sb.append("	}\r\n");
				sb.append("\r\n");	
			}else{
				sb.append("	@Override\r\n");
				sb.append("	public "+fbName+" findOne("+type+" id) {\r\n");
				sb.append("		return this."+fsName+"Repository.find"+fbName+"By"+getFirstBigName(getIdName(pojoAttrList))+"(id);\r\n");
				sb.append("	}\r\n");
				sb.append("\r\n");
			}
			
		}
		sb.append("	@Override\r\n");
		sb.append("	public Page<"+fbName+"> findAll(final Map<String, Object> param, Pageable pageable) {\r\n");
		sb.append("\r\n");
		sb.append("		Specification<"+fbName+"> spec = new Specification<"+fbName+">() {\r\n");
		sb.append("\r\n");
		sb.append("			@Override\r\n");
		sb.append("			public Predicate toPredicate(Root<"+fbName+"> root, CriteriaQuery<?> query, CriteriaBuilder cb) {\r\n");
		sb.append("				List<Predicate> list = new ArrayList<Predicate>();\r\n");
		
		for(POJOAttr attr : pojoAttrList){
			if(attr.getType()==Type.LONG){
				sb.append("				Long "+attr.getName()+" = (Long)param.get(\""+attr.getName()+"\");\r\n");
				sb.append("				if("+attr.getName()+"!=null) {\r\n");
				sb.append("					list.add(cb.equal(root.get(\""+attr.getName()+"\"), "+attr.getName()+"));\r\n");
				sb.append("				}\r\n");
			}
			if(attr.getType()==Type.INT){
				sb.append("				Integer "+attr.getName()+" = (Integer)param.get(\""+attr.getName()+"\");\r\n");
				sb.append("				if("+attr.getName()+"!=null) {\r\n");
				sb.append("					list.add(cb.equal(root.get(\""+attr.getName()+"\"), "+attr.getName()+"));\r\n");
				sb.append("				}\r\n");
			}
			if(attr.getType()==Type.STRING){
				sb.append("				String "+attr.getName()+" = (String)param.get(\""+attr.getName()+"\");\r\n");
				sb.append("				if(StringUtils.isNotBlank("+attr.getName()+")) {\r\n");
				sb.append("					list.add(cb.like(root.get(\""+attr.getName()+"\"), \"%\"+"+attr.getName()+"+\"%\"));\r\n");
				sb.append("				}\r\n");
			}
			if(attr.getType()==Type.DATE){
				sb.append("				Date "+attr.getName()+"Start = (Date)param.get(\""+attr.getName()+"Start\");\r\n");
				sb.append("				Date "+attr.getName()+"End = (Date)param.get(\""+attr.getName()+"End\");\r\n");
				
				sb.append("				if("+attr.getName()+"Start != null) {\r\n");
				sb.append("					list.add(cb.greaterThanOrEqualTo(root.get(\""+attr.getName()+"\"), "+attr.getName()+"Start));\r\n");
				sb.append("				}\r\n");
				sb.append("				\r\n");
				sb.append("				if("+attr.getName()+"End != null) {\r\n");
				sb.append("					list.add(cb.lessThanOrEqualTo(root.get(\""+attr.getName()+"\"), "+attr.getName()+"End));\r\n");
				sb.append("				}\r\n");
				sb.append("				\r\n");
			}
		}
		sb.append("				Predicate[] p = new Predicate[list.size()];\r\n");
		sb.append("				query.where(list.toArray(p));\r\n");
		sb.append("				return query.getRestriction();\r\n");
		sb.append("			}\r\n");
		sb.append("			\r\n");
		sb.append("		};\r\n");
		sb.append("\r\n");
		sb.append("		Page<"+fbName+"> page = this."+fsName+"Repository.findAll(spec, pageable);\r\n");
		sb.append("		return page;\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	public "+fbName+" findOne(Map<String, Object> param) {\r\n");
		sb.append("		Specification<"+fbName+"> spec = new Specification<"+fbName+">() {\r\n");
		sb.append("\r\n");
		sb.append("			@Override\r\n");
		sb.append("			public Predicate toPredicate(Root<"+fbName+"> root, CriteriaQuery<?> query, CriteriaBuilder cb) {\r\n");
		sb.append("				List<Predicate> list = new ArrayList<Predicate>();\r\n");
		for(POJOAttr attr : pojoAttrList){
			if(attr.getType()==Type.LONG){
				sb.append("				Long "+attr.getName()+" = (Long)param.get(\""+attr.getName()+"\");\r\n");
				sb.append("				if("+attr.getName()+"!=null) {\r\n");
				sb.append("					list.add(cb.equal(root.get(\""+attr.getName()+"\"), "+attr.getName()+"));\r\n");
				sb.append("				}\r\n");
			}
			if(attr.getType()==Type.INT){
				sb.append("				Integer "+attr.getName()+" = (Integer)param.get(\""+attr.getName()+"\");\r\n");
				sb.append("				if("+attr.getName()+"!=null) {\r\n");
				sb.append("					list.add(cb.equal(root.get(\""+attr.getName()+"\"), "+attr.getName()+"));\r\n");
				sb.append("				}\r\n");
			}
			if(attr.getType()==Type.STRING){
				sb.append("				String "+attr.getName()+" = (String)param.get(\""+attr.getName()+"\");\r\n");
				sb.append("				if(StringUtils.isNotBlank("+attr.getName()+")) {\r\n");
				sb.append("					list.add(cb.like(root.get(\""+attr.getName()+"\"), \"%\"+"+attr.getName()+"+\"%\"));\r\n");
				sb.append("				}\r\n");
			}
			if(attr.getType()==Type.DATE){
				sb.append("				Date "+attr.getName()+"Start = (Date)param.get(\""+attr.getName()+"Start\");\r\n");
				sb.append("				Date "+attr.getName()+"End = (Date)param.get(\""+attr.getName()+"End\");\r\n");
				
				sb.append("				if("+attr.getName()+"Start != null) {\r\n");
				sb.append("					list.add(cb.greaterThanOrEqualTo(root.get(\""+attr.getName()+"\"), "+attr.getName()+"Start));\r\n");
				sb.append("				}\r\n");
				sb.append("				\r\n");
				sb.append("				if("+attr.getName()+"End != null) {\r\n");
				sb.append("					list.add(cb.lessThanOrEqualTo(root.get(\""+attr.getName()+"\"), "+attr.getName()+"End));\r\n");
				sb.append("				}\r\n");
				sb.append("				\r\n");
			}
		}
		sb.append("				Predicate[] p = new Predicate[list.size()];\r\n");
		sb.append("				query.where(list.toArray(p));\r\n");
		sb.append("				return query.getRestriction();\r\n");
		sb.append("			}\r\n");
		sb.append("			\r\n");
		sb.append("		};\r\n");
		sb.append("\r\n");
		sb.append("		List<"+fbName+"> list = this."+fsName+"Repository.findAll(spec);\r\n");
		sb.append("		\r\n");
		sb.append("		if(list.size() > 0) {\r\n");
		sb.append("			return list.get(0);\r\n");
		sb.append("		}\r\n");
		sb.append("		\r\n");
		sb.append("		return null;\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("}\r\n");

		try {
			fu.crFile(sb.toString(),servicePath+fbName+"ServiceImpl.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public void createProcessJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();
		
		/**
		 * 生成接口类
		 */
		sb.append("package "+packageName+"business.process;\r\n");
		sb.append("import java.util.Map;\r\n");
		sb.append("import org.springframework.data.domain.Page;\r\n");
		sb.append("import org.springframework.data.domain.Pageable;\r\n");
		sb.append("import "+packageName+"business.domain."+fbName+";\r\n");
		sb.append("public interface "+fbName+"Process {\r\n");
		sb.append("\r\n");
		sb.append("	public "+fbName+" save("+fbName+" entity);\r\n");
		sb.append("	\r\n");
		sb.append("	public void update("+fbName+" entity);\r\n");
		sb.append("\r\n");
		sb.append("	public void delete("+fbName+" entity);\r\n");
		sb.append("\r\n");
		if(idExists(pojoAttrList)){
			String type = "String";
			if(getIdType(pojoAttrList)==Type.INT){
				type = "Integer";
			}
			if(getIdType(pojoAttrList)==Type.LONG){
				type = "Long";
			}
			sb.append("	public "+fbName+" findOne("+type+" id);\r\n");
			sb.append("\r\n");
		}
		sb.append("	public "+fbName+" findOne(Map<String,Object> param);\r\n");
		sb.append("\r\n");
		sb.append("	public Page<"+fbName+"> findAll(Map<String, Object> param, Pageable pageable);\r\n");
		sb.append("	\r\n");
		sb.append("}\r\n");
		try {
			fu.crFile(sb.toString(),processPath+fbName+"Process.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		/**
		 * 生成实现类
		 */
		sb = new StringBuffer();
		sb.append("package "+packageName+"business.process;\r\n");
		sb.append("\r\n");
		sb.append("import java.util.Date;\r\n");
		sb.append("import java.util.HashMap;\r\n");
		sb.append("import java.util.List;\r\n");
		sb.append("import java.util.Map;\r\n");
		sb.append("import org.springframework.beans.factory.annotation.Autowired;\r\n");
		sb.append("import org.springframework.data.domain.Page;\r\n");
		sb.append("import org.springframework.data.domain.PageRequest;\r\n");
		sb.append("import org.springframework.data.domain.Pageable;\r\n");
		sb.append("import org.springframework.data.domain.Sort;\r\n");
		sb.append("import org.springframework.data.domain.Sort.Direction;\r\n");
		sb.append("import org.springframework.stereotype.Service;\r\n");
		sb.append("import org.springframework.transaction.annotation.Transactional;\r\n");
		sb.append("import "+packageName+"business.constants.WebConstants;\r\n");
		sb.append("import "+packageName+"business.service."+fbName+"Service;\r\n");
		sb.append("import "+packageName+"business.domain."+fbName+";\r\n");
		sb.append("\r\n");
		sb.append("@Service(\""+fsName+"Process\")\r\n");
		sb.append("@Transactional(readOnly = true)\r\n");
		sb.append("public class "+fbName+"ProcessImpl implements "+fbName+"Process {\r\n");
		sb.append("\r\n");
		sb.append("	@Autowired\r\n");
		sb.append("	private "+fbName+"Service "+fsName+"Service;\r\n");
		sb.append("	\r\n");
		sb.append("	@Override\r\n");
		sb.append("	@Transactional(readOnly = false)\r\n");
		sb.append("	public "+fbName+" save("+fbName+" entity) {\r\n");
		if(isStandardPojo){
			sb.append("		Date date = new Date();\r\n");
			sb.append("		entity.setCreateTime(date);\r\n");
			sb.append("		entity.setOperateTime(date);\r\n");
			sb.append("		entity.setState(WebConstants.COMMON_ENTITY_ENABLED);\r\n");
			sb.append("		\r\n");
		}
		sb.append("		return this."+fsName+"Service.save(entity);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	@Transactional(readOnly = false)\r\n");
		sb.append("	public void update("+fbName+" entity) {\r\n");
		if(isStandardPojo){
			sb.append("		Date date = new Date();\r\n");
			sb.append("		entity.setOperateTime(date);\r\n");
		}
		sb.append("		this."+fsName+"Service.update(entity);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	@Transactional(readOnly = false)\r\n");
		sb.append("	public void delete("+fbName+" entity) {\r\n");
		if(isStandardPojo){
			sb.append("		Date date = new Date();\r\n");
			sb.append("		entity.setOperateTime(date);\r\n");
		}
		sb.append("		this."+fsName+"Service.delete(entity);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		if(idExists(pojoAttrList)){
			String type = "String";
			if(getIdType(pojoAttrList)==Type.INT){
				type = "Integer";
			}
			if(getIdType(pojoAttrList)==Type.LONG){
				type = "Long";
			}
			sb.append("	@Override\r\n");
			sb.append("	public "+fbName+" findOne("+type+" id) {\r\n");
			sb.append("		return this."+fsName+"Service.findOne(id);\r\n");
			sb.append("	}\r\n");
		}
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	public Page<"+fbName+"> findAll(Map<String, Object> param, Pageable pageable) {\r\n");
		sb.append("		return this."+fsName+"Service.findAll(param, pageable);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	@Override\r\n");
		sb.append("	public "+fbName+" findOne(Map<String, Object> param) {\r\n");
		sb.append("		return this."+fsName+"Service.findOne(param);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("}\r\n");

		try {
			fu.crFile(sb.toString(),processPath+fbName+"ProcessImpl.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public void createRepositoryJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String fbName = getFirstBigName(curTable);
		String fsName = getFirstSmallName(curTable);
		StringBuffer sb = new StringBuffer();

		sb.append("package "+packageName+"business.repository;\r\n");
		sb.append("import "+packageName+"common.repository.CommonRepository;\r\n");
		sb.append("import "+packageName+"business.domain."+fbName+";\r\n");
		sb.append("public interface "+fbName+"Repository extends CommonRepository<"+fbName+", String> {\r\n");
		
		String type = "String";
		if(getIdType(pojoAttrList)==Type.INT){
			type = "Integer";
		}
		if(getIdType(pojoAttrList)==Type.LONG){
			type = "Long";
		}
		
		if(!type.equals("String")){
			sb.append("\r\n");
			sb.append("	"+fbName+" find"+fbName+"By"+getFirstBigName(getIdName(pojoAttrList))+"("+type+" id);\r\n");
			sb.append("\r\n");
		}
		sb.append("}\r\n");
		try {
			fu.crFile(sb.toString(),repositoryPath+fbName+"Repository.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
	private boolean idExists(List<POJOAttr> pojoAttrList){
		for(POJOAttr attr : pojoAttrList){
			if(attr.isPK()){
				return true;
			}
		}
		return false;
	}
	
	private String getIdName(List<POJOAttr> pojoAttrList){
		for(POJOAttr attr : pojoAttrList){
			if(attr.isPK()){
				return attr.getName();
			}
		}
		return null;
	}
	
	private Type getIdType(List<POJOAttr> pojoAttrList){
		for(POJOAttr attr : pojoAttrList){
			if(attr.isPK()){
				return attr.getType();
			}
		}
		return null;
	}
	
	/**
     * 下划线转驼峰法
     * @param line 源字符串
     * @param smallCamel 大小驼峰,是否为小驼峰 firstName  大驼峰是FirstName
     * @return 转换后的字符串
     */
	private static String underline2Camel(String line,boolean smallCamel){
        if(line==null||"".equals(line)){
            return "";
        }
        StringBuffer sb=new StringBuffer();
        Pattern pattern=Pattern.compile("([A-Za-z\\d]+)(_)?");
        Matcher matcher=pattern.matcher(line);
        while(matcher.find()){
            String word=matcher.group();
            sb.append(smallCamel&&matcher.start()==0?Character.toLowerCase(word.charAt(0)):Character.toUpperCase(word.charAt(0)));
            int index=word.lastIndexOf('_');
            if(index>0){
                sb.append(word.substring(1, index).toLowerCase());
            }else{
                sb.append(word.substring(1).toLowerCase());
            }
        }
        return sb.toString();
    }
    /**
     * 驼峰法转下划线
     * @param line 源字符串
     * @return 转换后的字符串
     */
    private static String camel2Underline(String line){
        if(line==null||"".equals(line)){
            return "";
        }
        line=String.valueOf(line.charAt(0)).toUpperCase().concat(line.substring(1));
        StringBuffer sb=new StringBuffer();
        Pattern pattern=Pattern.compile("[A-Z]([a-z\\d]+)?");
        Matcher matcher=pattern.matcher(line);
        while(matcher.find()){
            String word=matcher.group();
            sb.append(word.toUpperCase());
            sb.append(matcher.end()==line.length()?"":"_");
        }
        return sb.toString();
    }
    
}
